﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using VAdvantage.Classes;
using VAdvantage.Common;
//using ViennaAdvantage.Process;
//using System.Windows.Forms;
//using ViennaAdvantage.Model;
using VAdvantage.DataBase;
using VAdvantage.SqlExec;
using VAdvantage.Utility;
using System.Data;
using VAdvantage.Logging;
//using VAdvantage.Controller;
using VAdvantage.Model;
using VAdvantage.Grids;
using System.Windows;

namespace VAdvantage.Model
{
    public class CalloutContractQty : VAdvantage.Model.CalloutEngine
    {
        //	Debug Steps		
        /// <summary>
        ///
        /// </summary>
        /// <param name="ctx">Context</param>
        /// <param name="WindowNo">current Window No</param>
        /// <param name="mTab">Model Tab</param>
        /// <param name="mField">Model Field</param>
        /// <param name="value">The new value</param>
        /// <returns>Error message or ""</returns>
        public string Qty(Context ctx, int WindowNo, GridTab mTab, GridField mField, Object value)
        {
            if (IsCalloutActive() || value == null || value.ToString() == "" || value == DBNull.Value)
            {
                return "";
            }

            Decimal? price = Util.GetValueOfDecimal(mTab.GetValue("PriceActual"));
            Decimal? val = Util.GetValueOfDecimal(value);
            //
            Int32 C_Tax_ID = 0;
            Decimal Rate = Envs.ZERO;
            String LineAmount = "";
            Decimal TotalRate = Envs.ZERO;
            mTab.SetValue("LineNetAmt", Decimal.Multiply(price.Value, val.Value));
           
            C_Tax_ID = VAdvantage.Utility.Util.GetValueOfInt(mTab.GetValue("C_Tax_ID"));
            String sqltax = "select rate from c_tax WHERE c_tax_id=" + C_Tax_ID + "";
            Rate = VAdvantage.Utility.Util.GetValueOfDecimal(DB.ExecuteScalar(sqltax, null, null));
            Decimal LineNetAmt = Util.GetValueOfDecimal(mTab.GetValue("LineNetAmt"));
            TotalRate = Util.GetValueOfDecimal((Util.GetValueOfDecimal(LineNetAmt) * Util.GetValueOfDecimal(Rate)) / 100);
            TotalRate = Decimal.Round(TotalRate, 2);
            mTab.SetValue("taxamt", TotalRate);
            mTab.SetValue("GrandTotal", Decimal.Add(Decimal.Multiply(price.Value, val.Value), Util.GetValueOfDecimal(mTab.GetValue("TaxAmt"))));
            return "";
        }

    }
}
